package edu.uwosh.cs342.project4;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class AddFavActivity extends Activity{

	Button submit, cancel;
	double latCoord, lonCoord;
	TextView lat;
	TextView lon;
	TextView favName;
	String name;
	int lati, lngi;
	SQLiteDatabase writeDB;
	DBHelper db;

	
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.add);
		submit = (Button) findViewById(R.id.submitBtn);
		cancel = (Button) findViewById(R.id.cancelBtn);
		lat = (TextView) findViewById(R.id.curLatTxtBox);
		lon = (TextView) findViewById(R.id.curLongTxtBox);
		favName = (TextView) findViewById(R.id.favTxtBox);
		name = favName.getText().toString();
		lati = getIntent().getIntExtra("lat", 0);
		lngi = getIntent().getIntExtra("lng", 0);
		lon.setText(lngi + "");
		lat.setText(lati + "");
		db = new DBHelper(this);
		writeDB = db.getWritableDatabase();
		
		submit.setOnClickListener(new OnClickListener() {
			public void onClick(View v){
				String name = favName.getText().toString();
				String insert = "insert into favorites values(" + "'" + name + "'" + "," + lati + "," + lngi +")";
				writeDB.execSQL(insert);
				db.close();
				Intent manualIntent = new Intent(AddFavActivity.this, Project4Activity.class);
				startActivity(manualIntent);
			}
		});
		
	}
}
